package org.apache.camel.component.cmis;

import java.net.URI;
import java.util.Map;

import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.util.CastUtils;
import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A component for integrating with CMIS compliant content repositories
 */
public class CmisComponent extends DefaultComponent {
	
	private static final transient Logger	LOG	= LoggerFactory.getLogger(CmisComponent.class);
	
	@Override
	protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> properties) throws Exception {
		String repositoryUri;
		if (!properties.isEmpty()) {
			Map<Object, Object> params = CastUtils.cast(properties);
			URI remainingUri = URISupport.createRemainingURI(new URI(remaining), params);
			repositoryUri = remainingUri.toString();
		} else {
			repositoryUri = remaining;
		}
		LOG.debug("RepositoryUri: {}", repositoryUri);
		return new CmisEndpoint(uri, this, repositoryUri);
	}
}
